package pe.com.mowa.siscobsms.datos;

import java.io.IOException;
import java.sql.*;
import java.util.ArrayList;

import pe.com.mowa.siscobsms.bean.analista;
import pe.com.mowa.siscobsms.bean.persona;

import com.sun.xml.internal.ws.org.objectweb.asm.Type;
public class conAnalista {
	 
		
	public void setLocal(analista per) throws IOException, ClassNotFoundException, Exception
	{
			String schema;
			CallableStatement cs;
			Connection cn;
			schema = "";
			// prop.getProperty("smsnm.schema", "vas_prom");
			cs = null;
			
			int estado=0;
			
			try {
				System.out.print("BEGIN SET LOCAL");

					cn = new conexion().get_conection();
					String sentence ="{ ? = call \"siscobsms\".\"setLocal\"(?,?) }";
					cs = cn.prepareCall(sentence);
				  
     		        cs.registerOutParameter(1, Type.INT);
			        cs.setString(2, per.getNombre());
			        cs.setString(3, per.getDireccion());
					
					cs.execute();
     				estado = cs.getInt(1);
				
					cs.close();
					cn.close();
				
					System.out.print("OK SET LOCAL");
			    }
			catch (SQLException e) {
				System.out.print("ERROR FUE "+e.getMessage());
			}
	}
	
	
	
	public ArrayList getLocales() throws Exception {

		CallableStatement cs;
		Connection cn;
		cs = null;
		cn = null;
		System.out.print("\n Antes de while datos locales -1");
		cn =  new conexion().get_conection();
		ResultSet rs = null;
		ArrayList locales = new ArrayList();

		try {
			System.out.print("\n Antes de while datos locales 0.....pp");
			String sentence ="select * from  \"siscobsms\".\"getLocales\"()";
			System.out.print("\n Query es "+sentence);
			cs = cn.prepareCall(sentence);
			cs.execute();
			rs = cs.getResultSet();
			analista loc;
			System.out.print("\n Antes de while datos locales 1");
			while (rs.next()) {
				loc = new analista(); 
				loc.setId(rs.getInt("idlocal"));
				loc.setNombre(rs.getString("nombre"));
				loc.setDireccion(rs.getString("direccion"));
				locales.add(loc);
				System.out.print("\n local "+loc.getNombre());

				//System.out.print("\n Dato persona es :"+per.getId()+" / "+per.getNombre()+" / "+per.getApePat()+" / "+per.getApeMat()+" / "+per.getDireccion()+" / "+per.getTel1()+" / "+per.getTel2());
			}

		} catch (Exception e) {
			
			System.out.print("\n Error fue"+e.getMessage());

		}

		cs.close();
		cn.close();

		return locales;
	}

	
}